package com.yxj07;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

public class TreeSetDemo {
    public static void main(String[] args) {
        //创建TreeSet对象,通过比较器进行排序
/*        TreeSet<Student> ts = new TreeSet<Student>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //int num = (o2.getChinese()+o2.getMath())-(o1.getChinese()+o1.getMath());
                int num = o2.getSum() - o1.getSum();
                int num1 = num == 0 ? o1.getChinese()-o2.getChinese() : num;
                int num2 = num1 == 0 ? o1.getName().compareTo(o2.getName()) : num1;
                return num2;
            }
        });*/
        TreeSet<Student> ts = new TreeSet<Student>();
        //创建学生对象
        Student s1 = new Student("林青霞",98,100);
        Student s2 = new Student("西施",78,88);
        Student s3 = new Student("庄周",77,86);
        Student s4 = new Student("鲁班",69,189);
        Student s5 = new Student("杨雪娇",58,78);
        Student s6 = new Student("杨美",59,77);
        Student s7 = new Student("杨美美",58,78);
        ts.add(s1);
        ts.add(s2);
        ts.add(s3);
        ts.add(s4);
        ts.add(s5);
        ts.add(s6);
        ts.add(s7);
        for(Student s : ts) {
            System.out.println(s.getName()+","+s.getChinese()+","+s.getMath()+","+s.getSum());
        }
    }
}
